package com.zhongchaowuye.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.zhongchaowuye.pojo.A_ZD;
import com.zhongchaowuye.service.A_ZDService;

@Controller
@RequestMapping("/a_ZD")
public class A_ZDController {

	@Resource
	private A_ZDService a_ZDService;
	
	@RequestMapping(value ="/getA_ZD",method = RequestMethod.POST)
	@ResponseBody
	//根据id获取A_ZD对象信息
	public Map<String,Object> getA_ZD(HttpServletRequest request,A_ZD zd){
		Map<String,Object> m=new HashMap<>();
		Map<String,Object> reMap=new HashMap<>();
		try {
			A_ZD a_ZD=a_ZDService.getA_ZD(zd);
			reMap.put("a_ZD", a_ZD);
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR："+e.getMessage());
		}
		return reMap;
	}

	@RequestMapping(value ="/getA_ZDList",method = RequestMethod.POST)
	@ResponseBody
	//获取列表
	public Map<String,Object> getA_ZDList(HttpServletRequest request,A_ZD a_ZD){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			List<Map<String,Object>> rList=a_ZDService.getA_ZDList(a_ZD); //不带分页（注意实现类中的相应写法）
			//Page<Map<String,Object>> rList = (Page)a_ZDService.getA_ZDList(a_ZD);
			
			//System.out.println(rList);
			reMap.put("rows", rList);
			//reMap.put("total", rList.getTotal());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/insertA_ZD",method = RequestMethod.POST)
	@ResponseBody
	//添加
	public Map<String,Object> insertA_ZD(HttpServletRequest request,A_ZD a_ZD)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_ZDService.insertA_ZD(a_ZD);
			//int flag = 0;
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/updateA_ZD",method = RequestMethod.POST)
	@ResponseBody
	//修改
	public Map<String,Object> updateA_ZD(HttpServletRequest request,A_ZD a_ZD)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_ZDService.updateA_ZD(a_ZD);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/delA_ZD",method = RequestMethod.POST)
	@ResponseBody
	//软删除
	public Map<String,Object> delA_ZD(HttpServletRequest request,A_ZD a_ZD)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		Map<String,Object> m=new HashMap<>();
		try 
		{
			int flag=a_ZDService.delA_ZD(a_ZD);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
}
